package com.csdj.web.listener;

import com.csdj.entity.Department;
import com.csdj.service.DeptService;
import com.csdj.service.impl.DeptServiceImpl;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.List;

/**
 * packageName com.csdj.web.listener
 *
 * @author winver
 * @version 1.0
 * @className MySessionListener
 * @date 2024/11/28
 * @description TODO
 */
@WebListener
public class MySessionListener implements HttpSessionListener {
    @Override
    public void sessionCreated(HttpSessionEvent se) {
        System.out.println("会话监听器第一个");
        HttpSession session = se.getSession();

        //调用业务层
        DeptService deptService  = new DeptServiceImpl();
        List<Department> depts = deptService.findAllDepts();
        session.setAttribute("depts",depts);
    }

}
